package ru.xeden.web.html.component;

import java.util.Arrays;
import java.util.Map;


/**
 * Соллекция фабрик компонентов
 * @author evga
 *
 */
public class ComponentFactoryCollection
    implements IComponentFactory
{
    private IComponentFactory [] factories;

    public static ComponentFactoryCollection newInstance(IComponentFactory... factories)
    {
        return new ComponentFactoryCollection(factories);
    }

    private ComponentFactoryCollection(IComponentFactory... factories)
    {
        this.factories = Arrays.copyOf(factories, factories.length);
    }

    public IComponent createComponent(String id, Map<String, String> atts)
    {
        for (IComponentFactory factory : factories)
        {
            IComponent component = factory.createComponent(id, atts);
            if (component != null)
            {
                return component;
            }
        }
        return null;
    }
}
